package com.okb.utils;

import com.okb.bean.CandleDataBean;
import com.okb.bean.WebSocketResponse;

import java.util.ArrayList;
import java.util.List;

/**
 * Description: k线响应数据转化
 * Author: hcxu
 * Time: 2024/11/20 4:18 PM
 */
public class WebSocketResponseParser {
    public static List<CandleDataBean> parseData(WebSocketResponse response) {
        List<CandleDataBean> candles = new ArrayList<>();
        if (response.getData() != null) {
            for (List<String> record : response.getData()) {
                CandleDataBean candle = new CandleDataBean();
                candle.setCandleName(response.getArg().getInstId());
                candle.setTimestamp(Long.parseLong(record.get(0)));
                candle.setOpen(record.get(1));
                candle.setHigh(record.get(2));
                candle.setLow(record.get(3));
                candle.setClose(record.get(4));
                candle.setVolume(record.get(5));
                candle.setVolumeCcy(Double.parseDouble(record.get(6)));
                candle.setVolumeCcyQuote(Double.parseDouble(record.get(7)));
                candle.setConfirm(Integer.parseInt(record.get(8)));
                candles.add(candle);
            }
        }
        return candles;
    }
}
